﻿// -----------------------------
// Copyright © Kodi Studios 2011
// -----------------------------

using System.IO;
using System.Net;
using System.Text.RegularExpressions;
using System.Collections.Generic;

namespace Kodi.Picturethrill
{
    class BingImageProvider : IImageProvider
    {
        static List<string> bingUrls =new List<string>(new string[]{
            "http://www.bing.com", 
            //"http://www.bing.co.jp",
            //"http://www.bing.co.uk",
            // TODO: Bing in other countries is pretty similar
            // so until we figure out how to dupe images properly,
            // don't use other bing sites.
            //"http://www.bing.de",
            //"http://www.bing.ru",
            //"http://cn.bing.com",
            //"http://br.bing.com",
            //"http://www.bing.fr",
            //"http://www.bing.in",
            //"http://www.bing.sg",
        });

        List<string> imageUrls = new List<string>();

        public BingImageProvider()
        {
        }

        public IList<string> ImageUrls
        {
            get
            {
                if (this.imageUrls.Count == 0)
                {
                    foreach (string bingUrl in bingUrls)
                    {
                        // ExampleMatch: g_img={url:'/az/hprichbg?p=rb%2fMtPinatubo_JA-JP1604833133.jpg',
                        imageUrls.Add(HtmlUtilities.GetImageUrl(bingUrl, new Regex(@"g_img\=\{url\:\'([^\']+)\'")));
                    }
                }
                return imageUrls;
            }
        }

        public string Name
        {
            get
            {
                return "Bing";
            }
        }

        public string SiteName
        {
            get
            {
                return bingUrls[0];
            }
        }
    }
}
